package com.itheima.controller;

import com.itheima.domain.SmsFlashPromotionSession;
import com.itheima.manager.SmsFlashSessionManager;
import com.itheima.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ChenTianSui
 * @date 2022/11/12 10:24
 */
@RestController
@RequestMapping("/flashSession")
public class SmsFlashSessionController {
    @Autowired
    private SmsFlashSessionManager smsFlashSessionManager;

    /**
     * 获取全部场次
     *
     * @return
     */
    @GetMapping("/list")
    public R<List<SmsFlashPromotionSession>> findList() {
        return smsFlashSessionManager.findList();

    }

    /**
     * 修改启用状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public R updateStatus(@PathVariable Integer id, @RequestParam(required = false) Integer status) {
        return smsFlashSessionManager.updateStatus(id, status);

    }

    /**
     * 添加场次
     *
     * @param
     * @return
     */
    @PostMapping("/create")
    public R create(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession) {
        return smsFlashSessionManager.create(smsFlashPromotionSession);

    }

    /**
     * 删除场次
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        return smsFlashSessionManager.delete(id);

    }

    /**
     * 修改场次
     *
     * @return
     */
    @PostMapping("/update/{id}")
    public R update(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession) {
        return smsFlashSessionManager.update(smsFlashPromotionSession);

    }

    /**
     * 根据id获取场次详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<SmsFlashPromotionSession> findById(@PathVariable Integer id) {
        return smsFlashSessionManager.findById(id);

    }

    @GetMapping("/selectList")
    public R<List<Map<String, Object>>> selectList(@RequestParam(required = false) Integer flashPromotionId) {
        return smsFlashSessionManager.selectList(flashPromotionId);

    }


}
 
